﻿using WhaleAccount.Contracts.Services;
using WhaleAccount.Helpers;
using Type = WhaleAccount.Models.Type;

namespace WhaleAccount.Services;
public class TypeService : ITypeService
{
    private readonly DatabaseContext _dbContext;
    private IEnumerable<Type> types;

    public TypeService()
    {
        _dbContext = DatabaseContext.GetDbContext();
    }

    async Task<IEnumerable<Type>> ITypeService.GetTypeListAsync()
    {
        types ??= _dbContext.Types;

        await Task.CompletedTask;
        return types;
    }


    async Task<int> ITypeService.UpdateTypeAsync(Type type)
    {
        _dbContext.Types.Update(type);

        var count = _dbContext.SaveChanges();

        await Task.CompletedTask;
        return count;
    }

}
